package com.hq.ims.data.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.BusInfoFeedback;
import com.hq.ims.data.entity.BusInfoForewarning;
import com.hq.ims.data.entity.BusInfoNotification;
import com.hq.ims.data.entity.BusiInfo;
import com.hq.ims.data.entityenum.*;
import com.hq.ims.data.vo.auth.BaseRowAuthVo;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 蒋柏平
 * @since 20241114
 */
@Mapper
public interface BusInfoForewarningMapstruct {

    BusInfoForewarningMapstruct INSTANCE = Mappers.getMapper(BusInfoForewarningMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    BusInfoForewarningVo toBusInfoForewarningVo(BusInfoForewarning source);

    default List<BusInfoForewarningVo> toBusInfoForewarningVoList(List<BusInfoForewarning> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toBusInfoForewarningVo).collect(Collectors.toList());
    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "预警公司列表Vo")
    @Data
    class ForewarningCompanyVo {

        @ApiModelProperty(value = "公司id")
        private String companyId;

        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @ApiModelProperty(value = "上级公司名称")
        private String parentName;

        @ApiModelProperty(value = "公司地址")
        private String companyAddress;

        @ApiModelProperty(value = "地区")
        private String city;

        @ApiModelProperty(value = "产业标记")
        private String industryName;

        @ApiModelProperty(value = "预警信息列表")
        private List<BusInfoForewarningVo> busInfoForewarningVoList;
    }

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class BusInfoForewarningVo {
        @ApiModelProperty(value = "预警id")
        private String busInfoForewarningId;

        @ApiModelProperty(value = "经营信息ID")
        private String busiInfoId;

        @ApiModelProperty(value = "项目名称")
        private String projectName;

        @ApiModelProperty(value = "产业标记")
        private String industryMarkName;

        @ApiModelProperty(value = "推送公司")
        private String pushCompanyName;

        @ApiModelProperty(value = "业主方公司名称")
        private String ownerCompanyName;

        @ApiModelProperty(value = "施工方公司名称")
        private String constructionName;

        @ApiModelProperty(value = "项目地址名称")
        @TableField(value = "project_address_name")
        private String projectAddressName;

        @ApiModelProperty(value = "预计产值规模")
        private BigDecimal outputScale;

        @ApiModelProperty(value = "项目阶段")
        private EnumProjectPhase projectStage;

        @ApiModelProperty(value = "派生信息标签")
        private EnumRootInformation rootInformationTag;

        @ApiModelProperty(value = "信息类型")
        private EnumBusinessTypeStatus infoType;

        @ApiModelProperty(value = "省份")
        private String province;

        @ApiModelProperty(value = "城市")
        private String city;

        @ApiModelProperty(value = "发布人")
        private String publisher;

        @ApiModelProperty(value = "发布时间")
        private LocalDateTime publishTime;

        @ApiModelProperty(value = "经营人员名称")
        private String busiPersonName;

        @ApiModelProperty(value = "反馈时间")
        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime feedbackDate;

        @ApiModelProperty(value = "反馈阶段")
        private EnumFeedbackPhase feedbackPhase;

        @ApiModelProperty(value = "预警信息分类")
        private EnumForewarningInfoClassify forewarningInfoClassify;

        @ApiModelProperty(value = "反馈预警结束时间")
        private LocalDateTime feedbackForewarningEndDate;

        @ApiModelProperty(value = "发送短信的用户ID")
        private String sendMessageUserId;

        @ApiModelProperty(value = "是否已发送短信")
        private Boolean sendFlag;

        @ApiModelProperty(value = "发送短信的用户名称")
        private String userRealName;

        @ApiModelProperty(value = "发送短信手机号码")
        private String mobile;

        @ApiModelProperty(value = "短信code")
        private String smsCode;

        @ApiModelProperty(value = "预警时长小时")
        private Integer timeHour;
    }

    @ApiModel(value = "未接收预警详情Vo")
    @Data
    class NotReceiveDetailVo extends BusiInfo {
        @ApiModelProperty(value = "预警id")
        private String busInfoForewarningId;

        @ApiModelProperty(value = "反馈阶段")
        private EnumFeedbackPhase feedbackPhase;

        @ApiModelProperty(value = "反馈时间")
        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime feedbackDate;

        @ApiModelProperty(value = "未接收预警结束时间")
        private LocalDateTime receiveForewarningEndDate;

        @ApiModelProperty(value = "接收情况")
        private List<BusiIndustryAssignMapstruct.BusiIndustryAssignVo> busiIndustryAssignVoList;
    }

    @ApiModel(value = "未反馈预警详情Vo")
    @Data
    class NotFeedbackDetailVo extends BusiInfo {
        @ApiModelProperty(value = "预警id")
        private String busInfoForewarningId;

        @ApiModelProperty(value = "经营人员名称")
        private String busiPersonName;

        @ApiModelProperty(value = "反馈时间")
        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime feedbackDate;

        @ApiModelProperty(value = "反馈阶段")
        private EnumFeedbackPhase feedbackPhase;

        @ApiModelProperty(value = "未反馈预警结束时间")
        private LocalDateTime feedbackForewarningEndDate;

        @ApiModelProperty(value = "反馈情况")
        private List<BusiIndustryAssignMapstruct.BusiIndustryAssignVo> busiIndustryAssignVoList;
    }

    @ApiModel(value = "行级权限对象")
    @Data
    class BusInfoForewarningRowAuthVo extends BaseRowAuthVo {

        //自定义其它行级权限


        //构造函数
        public BusInfoForewarningRowAuthVo(BusInfoForewarning entity) {
            //当前操作用户ID
            String userId = AppUtils.getUserId();
            //是否创建者
            boolean isCreateUser = entity.getCreateUserId().equals(userId);

            //设置编辑( 是创者者 )
            super.setIsCanEdit(isCreateUser);

            //设置删除( 是创者者 )
            super.setIsCanDel(isCreateUser);
        }

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

        @ApiModelProperty(value = "公司Id")
        private String companyId;

        @ApiModelProperty(value = "公司名称")
        private String companyName;

        @ApiModelProperty(value = "产业标记")
        private List<String> industryNameList;

        @ApiModelProperty(value = "项目名称")
        private String projectName;

        @ApiModelProperty(value = "预警信息分类")
        private EnumForewarningInfoClassify forewarningInfoClassify;

        @ApiModelProperty(value = "项目阶段")
        private EnumProjectPhase projectStage;

        @ApiModelProperty(value = "派生信息标签")
        private EnumRootInformation rootInformationTag;

        @ApiModelProperty(value = "发布时间排序")
        private String publishTimeSort;
    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

        @NotBlank(message = "数据ID不能为空", groups = {VdEdit.class})
        @ApiModelProperty(value = "数据ID")
        private String busInfoForewarningId;

        @ApiModelProperty(value = "经营信息ID")
        private String busiInfoId;

        @ApiModelProperty(value = "产业标记ID")
        private String industryMarkId;

        @ApiModelProperty(value = "产业标记名称")
        private String industryMarkName;

        @ApiModelProperty(value = "企业ID")
        private String companyId;

        @ApiModelProperty(value = "企业名称")
        private String companyName;

        @ApiModelProperty(value = "数据id(根据信息分类, 确定是推送id还是跟踪id)")
        private String dataId;

        @ApiModelProperty(value = "预警信息分类")
        private EnumForewarningInfoClassify forewarningInfoClassify;

        @ApiModelProperty(value = "反馈阶段")
        private EnumFeedbackPhase feedbackPhase;

        @ApiModelProperty(value = "反馈时间")
        private LocalDateTime feedbackDate;

        @ApiModelProperty(value = "经营人员ID")
        private String busiPersonId;

        @ApiModelProperty(value = "经营人员名称")
        private String busiPersonName;

        @ApiModelProperty(value = "创建时间")
        private LocalDateTime createDateTime;

        @ApiModelProperty(value = "创建用户名称")
        private String createUserName;

        @ApiModelProperty(value = "更新时间")
        private LocalDateTime updateDateTime;

        @ApiModelProperty(value = "更新用户名称")
        private String updateUserName;

        @ApiModelProperty(value = "乐观锁")
        private Integer version;

        @ApiModelProperty(value = "是否删除")
        private Boolean isDel;

        @ApiModelProperty(value = "创建用户id")
        private String createUserId;

        @ApiModelProperty(value = "更新用户id")
        private String updateUserId;

        @ApiModelProperty(value = "组织机构ID")
        private String orgId;
    }

    @ApiModel(value = "添加预警Vo")
    @Data
    class AddForewarningVo {
        @ApiModelProperty(value = "预警信息分类")
        private EnumForewarningInfoClassify forewarningInfoClassify;

        @ApiModelProperty(value = "未接收对象")
        private BusInfoNotification busInfoNotification;

        @ApiModelProperty(value = "未反馈对象")
        private BusInfoFeedback busInfoFeedback;
    }

    @ApiModel(value = "发送预警短信Vo")
    @Data
    class ForewarningSmsVo {

        @NotBlank(message = "预警ID不能为空")
        @ApiModelProperty(value = "预警id")
        private String busInfoForewarningId;

        @NotBlank(message = "发送短信手机号码不能为空")
        @ApiModelProperty(value = "发送短信手机号码")
        private String mobile;

        @NotBlank(message = "短信code不能为空")
        @ApiModelProperty(value = "短信code")
        private String smsCode;

    }

    //-------------------------------- springboot验证标识 --------------------------------

}
